'\" t
.\"     Title: git-restore
.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
.\"      Date: 03/29/2020
.\"    Manual: Git Manual
.\"    Source: Git 2.26.0.106.g9fadedd637
.\"  Language: English
.\"
.TH "GIT\-RESTORE" "1" "03/29/2020" "Git 2\&.26\&.0\&.106\&.g9faded" "Git Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
git-restore \- Restore working tree files
.SH "SYNOPSIS"
.sp
.nf
\fIgit restore\fR [<options>] [\-\-source=<tree>] [\-\-staged] [\-\-worktree] [\-\-] <pathspec>\&...
\fIgit restore\fR [<options>] [\-\-source=<tree>] [\-\-staged] [\-\-worktree] \-\-pathspec\-from\-file=<file> [\-\-pathspec\-file\-nul]
\fIgit restore\fR (\-p|\-\-patch) [<options>] [\-\-source=<tree>] [\-\-staged] [\-\-worktree] [\-\-] [<pathspec>\&...]
.fi
.sp
.SH "DESCRIPTION"
.sp
Restore specified paths in the working tree with some contents from a restore source\&. If a path is tracked but does not exist in the restore source, it will be removed to match the source\&.
.sp
The command can also be used to restore the content in the index with \fB\-\-staged\fR, or restore both the working tree and the index with \fB\-\-staged \-\-worktree\fR\&.
.sp
By default, the restore sources for working tree and the index are the index and \fBHEAD\fR respectively\&. \fB\-\-source\fR could be used to specify a commit as the restore source\&.
.sp
See "Reset, restore and revert" in \fBgit\fR(1) for the differences between the three commands\&.
.sp
THIS COMMAND IS EXPERIMENTAL\&. THE BEHAVIOR MAY CHANGE\&.
.SH "OPTIONS"
.PP
\-s <tree>, \-\-source=<tree>
.RS 4
Restore the working tree files with the content from the given tree\&. It is common to specify the source tree by naming a commit, branch or tag associated with it\&.
.sp
If not specified, the default restore source for the working tree is the index, and the default restore source for the index is
\fBHEAD\fR\&. When both
\fB\-\-staged\fR
and
\fB\-\-worktree\fR
are specified,
\fB\-\-source\fR
must also be specified\&.
.RE
.PP
\-p, \-\-patch
.RS 4
Interactively select hunks in the difference between the restore source and the restore location\&. See the \(lqInteractive Mode\(rq section of
\fBgit-add\fR(1)
to learn how to operate the
\fB\-\-patch\fR
mode\&.
.sp
Note that
\fB\-\-patch\fR
can accept no pathspec and will prompt to restore all modified paths\&.
.RE
.PP
\-W, \-\-worktree, \-S, \-\-staged
.RS 4
Specify the restore location\&. If neither option is specified, by default the working tree is restored\&. Specifying
\fB\-\-staged\fR
will only restore the index\&. Specifying both restores both\&.
.RE
.PP
\-q, \-\-quiet
.RS 4
Quiet, suppress feedback messages\&. Implies
\fB\-\-no\-progress\fR\&.
.RE
.PP
\-\-progress, \-\-no\-progress
.RS 4
Progress status is reported on the standard error stream by default when it is attached to a terminal, unless
\fB\-\-quiet\fR
is specified\&. This flag enables progress reporting even if not attached to a terminal, regardless of
\fB\-\-quiet\fR\&.
.RE
.PP
\-\-ours, \-\-theirs
.RS 4
When restoring files in the working tree from the index, use stage #2 (\fIours\fR) or #3 (\fItheirs\fR) for unmerged paths\&.
.sp
Note that during
\fBgit rebase\fR
and
\fBgit pull \-\-rebase\fR,
\fIours\fR
and
\fItheirs\fR
may appear swapped\&. See the explanation of the same options in
\fBgit-checkout\fR(1)
for details\&.
.RE
.PP
\-m, \-\-merge
.RS 4
When restoring files on the working tree from the index, recreate the conflicted merge in the unmerged paths\&.
.RE
.PP
\-\-conflict=<style>
.RS 4
The same as
\fB\-\-merge\fR
option above, but changes the way the conflicting hunks are presented, overriding the
\fBmerge\&.conflictStyle\fR
configuration variable\&. Possible values are "merge" (default) and "diff3" (in addition to what is shown by "merge" style, shows the original contents)\&.
.RE
.PP
\-\-ignore\-unmerged
.RS 4
When restoring files on the working tree from the index, do not abort the operation if there are unmerged entries and neither
\fB\-\-ours\fR,
\fB\-\-theirs\fR,
\fB\-\-merge\fR
or
\fB\-\-conflict\fR
is specified\&. Unmerged paths on the working tree are left alone\&.
.RE
.PP
\-\-ignore\-skip\-worktree\-bits
.RS 4
In sparse checkout mode, by default is to only update entries matched by
\fB<pathspec>\fR
and sparse patterns in $GIT_DIR/info/sparse\-checkout\&. This option ignores the sparse patterns and unconditionally restores any files in
\fB<pathspec>\fR\&.
.RE
.PP
\-\-overlay, \-\-no\-overlay
.RS 4
In overlay mode, the command never removes files when restoring\&. In no\-overlay mode, tracked files that do not appear in the
\fB\-\-source\fR
tree are removed, to make them match
\fB<tree>\fR
exactly\&. The default is no\-overlay mode\&.
.RE
.PP
\-\-pathspec\-from\-file=<file>
.RS 4
Pathspec is passed in
\fB<file>\fR
instead of commandline args\&. If
\fB<file>\fR
is exactly
\fB\-\fR
then standard input is used\&. Pathspec elements are separated by LF or CR/LF\&. Pathspec elements can be quoted as explained for the configuration variable
\fBcore\&.quotePath\fR
(see
\fBgit-config\fR(1))\&. See also
\fB\-\-pathspec\-file\-nul\fR
and global
\fB\-\-literal\-pathspecs\fR\&.
.RE
.PP
\-\-pathspec\-file\-nul
.RS 4
Only meaningful with
\fB\-\-pathspec\-from\-file\fR\&. Pathspec elements are separated with NUL character and all other characters are taken literally (including newlines and quotes)\&.
.RE
.PP
\-\-
.RS 4
Do not interpret any more arguments as options\&.
.RE
.PP
<pathspec>\&...
.RS 4
Limits the paths affected by the operation\&.
.sp
For more details, see the
\fIpathspec\fR
entry in
\fBgitglossary\fR(7)\&.
.RE
.SH "EXAMPLES"
.sp
The following sequence switches to the \fBmaster\fR branch, reverts the \fBMakefile\fR to two revisions back, deletes hello\&.c by mistake, and gets it back from the index\&.
.sp
.if n \{\
.RS 4
.\}
.nf
$ git switch master
$ git restore \-\-source master~2 Makefile  \fB(1)\fR
$ rm \-f hello\&.c
$ git restore hello\&.c                     \fB(2)\fR
.fi
.if n \{\
.RE
.\}
.sp
.sp
\fB1. \fRtake a file out of another commit
.br
\fB2. \fRrestore hello\&.c from the index
.br
.sp
If you want to restore \fIall\fR C source files to match the version in the index, you can say
.sp
.if n \{\
.RS 4
.\}
.nf
$ git restore \(aq*\&.c\(aq
.fi
.if n \{\
.RE
.\}
.sp
.sp
Note the quotes around \fB*\&.c\fR\&. The file \fBhello\&.c\fR will also be restored, even though it is no longer in the working tree, because the file globbing is used to match entries in the index (not in the working tree by the shell)\&.
.sp
To restore all files in the current directory
.sp
.if n \{\
.RS 4
.\}
.nf
$ git restore \&.
.fi
.if n \{\
.RE
.\}
.sp
.sp
or to restore all working tree files with \fItop\fR pathspec magic (see \fBgitglossary\fR(7))
.sp
.if n \{\
.RS 4
.\}
.nf
$ git restore :/
.fi
.if n \{\
.RE
.\}
.sp
.sp
To restore a file in the index to match the version in \fBHEAD\fR (this is the same as using \fBgit-reset\fR(1))
.sp
.if n \{\
.RS 4
.\}
.nf
$ git restore \-\-staged hello\&.c
.fi
.if n \{\
.RE
.\}
.sp
.sp
or you can restore both the index and the working tree (this the same as using \fBgit-checkout\fR(1))
.sp
.if n \{\
.RS 4
.\}
.nf
$ git restore \-\-source=HEAD \-\-staged \-\-worktree hello\&.c
.fi
.if n \{\
.RE
.\}
.sp
.sp
or the short form which is more practical but less readable:
.sp
.if n \{\
.RS 4
.\}
.nf
$ git restore \-s@ \-SW hello\&.c
.fi
.if n \{\
.RE
.\}
.sp
.SH "SEE ALSO"
.sp
\fBgit-checkout\fR(1), \fBgit-reset\fR(1)
.SH "GIT"
.sp
Part of the \fBgit\fR(1) suite
